package com.example.weblending.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.weblending.domain.File;
import com.example.weblending.domain.Task;
import com.example.weblending.service.TaskService;
import com.example.weblending.mapper.TaskMapper;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;

/**
 *
 */
@Service
public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task>
implements TaskService{

    @Override
    public int quickCleanTask(int uid) {
        Task task=new Task();
        task.setName("文件清洗");
        task.setStarttime(new Timestamp(System.currentTimeMillis()));
        task.setState(0);
        task.setOid(uid);
        this.save(task);
        return task.getId();
    }

    @Override
    public int quickAnalyzeTask(int uid) {
        Task task=new Task();
        task.setName("文件分析");
        task.setStarttime(new Timestamp(System.currentTimeMillis()));
        task.setState(0);
        task.setOid(uid);
        this.save(task);
        return task.getId();
    }

    @Override
    public void finishCleanTask(File file) {
        Task task=getById(file.getTask());
        task.setEndtime(new Timestamp(System.currentTimeMillis()));
        task.setState(1);
        task.setDescption(file.getName()+ " 清理完成");
        this.updateById(task);
    }

    @Override
    public void finishAnalyzeTask(File file) {
        Task task=getById(file.getTask());
        task.setEndtime(new Timestamp(System.currentTimeMillis()));
        task.setState(1);

        task.setDescption(file.getName()+ " 分析完成");
        System.out.println(task.getDescption());
        this.updateById(task);
    }
}




